﻿
using System;
using System.Collections.Generic;
using System.Text;

using YouHP.Utility;
using YouHP.BLL;
using YouHP.Model;
using YouHP.Model.Group;
using System.Web;

namespace YouHP.Pages.BBS
{
    public class Index : YouHP.Pages.BasePage
    {
        protected override void ShowPage()
        {
            base.ShowPage();
            if(ErrorCount > 0) return;
            
            HandleCommon();
            if(ErrorCount > 0) return;
            
            if(IsPost) HandlePost();
            else HandleGet();
        }

        protected List<GroupInfo> GroupList;
        protected int PageCount;
        protected int PageIndex;
        protected int PageSize = 20;
        protected string PagingString = "";
        protected int DataCount = 0;
        protected List<TopicInfo> TopicDataListHottest;
        protected List<TopicInfo> TopicDataListLatest;
        protected List<ActionInfo> ActionLatestList;
        protected int n = 10;

        protected PatientRecordInfo PrData;
        protected GroupInfo GroupData;

        protected void HandleCommon()
        {
            this.SetTitle("论坛");
            this.AddLocation("论坛", "/BBS/Index.aspx");
        }
        
        protected void HandlePost()
        {
            
        }
        
        protected void HandleGet()
        {
            PageIndex = RequestTools.GetQueryInt("page", 1);
            GroupList = GroupBLL.Instance.GetSystemGroupList(PageSize, PageIndex, out DataCount);
            TopicDataListHottest = TopicBLL.Instance.GetHottestTopic(n);
            TopicDataListLatest = TopicBLL.Instance.GetLastestTopic(n);
            ActionLatestList = ActionBLL.Instance.GetLattestHugBookList(n);

            string query = HttpContext.Current.Request.Url.Query;
            query = Utils.RemoveQueryItem(query, "page");

            PageCount = Utils.GetPageCount(DataCount, PageSize);

            PagingString = this.GetPagingString(
                PageIndex,
                PageCount,
                "/BBS/Index.aspx" + query, "page");

            if(UserData.Id > 0)
            {
                PrData = PatientBLL.Instance.GetPatientRecordInfo(UserData.Id);
                if(PrData.Id > 0)
                {
                    GroupData = GroupBLL.Instance.GetRecommendedSystemGroup(PrData.DiseaseId);
                }
            }
		}      
    }
}